package com.rzj.sys_lab_assistant.service.impl;

import com.rzj.sys_lab_assistant.dao.AssistantRepairMapper;
import com.rzj.sys_lab_assistant.entity.bo.ExportBO;
import com.rzj.sys_lab_assistant.service.IAssistantRepairService;
import com.rzj.sys_lab_assistant.service.IExportService;
import com.rzj.sys_lab_assistant.utils.ExportWordUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: sys_lab_assistant
 * @description:
 * @author: 作者
 * @create: 2021-07-04 11:05
 */
@Service
public class ExportServiceImpl implements IExportService {

    @Autowired
    AssistantRepairMapper assistantRepairMapper;

    ExportWordUtils exportWordUtils;

    @Override
    public void downloadMedicalRecord(int repairId, HttpServletRequest request, HttpServletResponse response) throws IllegalAccessException, IOException {
        ExportBO export = assistantRepairMapper.exportById(repairId);
        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd");
        Map<String,Object> params = new HashMap<>();
        params.put("departmentName",export.getDepartmentName() == null ? "暂无": export.getDepartmentName());
        params.put("equipmentName",export.getEquipmentName() == null ? "暂无": export.getEquipmentName());
        params.put("labName",export.getLabName() == null ? "暂无": export.getLabName());
        params.put("equipmentNo",export.getEquipmentNo() == null ? "暂无": export.getEquipmentNo());
        params.put("repairName", export.getRepairName() == null ? "暂无": export.getRepairName());
        params.put("errorContent",export.getErrorContent() == null ? "暂无": export.getErrorContent());
        params.put("repairTime",export.getRepairTime() == null ? "暂无": dateFormat.format(export.getRepairTime()));

        exportWordUtils.exportWord("C:/Users/Lenovo/Desktop/export.docx","test","梧州学院维修申请表("+repairId+").docx",params,request,response);

    }

}
